import java.io.IOException;
import java.util.Arrays;

public class Main{

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {

		java.io.BufferedReader r = new java.io.BufferedReader(
				new java.io.InputStreamReader(System.in));

		int number = Integer.parseInt(r.readLine());
		int[] men;
		int[] women;
		for (int i = 0; i < number; i++) {
			int n = Integer.parseInt(r.readLine());
			men = new int[n];
			women = new int[n];

			String[] s = (r.readLine().trim()).split(" ");
			String[] s1 = (r.readLine().trim()).split(" ");
			int sum = 0;
			for (int j = 0; j < n; j++) {
				men[j] = Integer.parseInt(s[j]);
				women[j] = Integer.parseInt(s1[j]);
			}
			Arrays.sort(men);
			Arrays.sort(women);
			for (int j = 0; j < n; j++) {
				sum += men[j] * women[j];
			}

			System.out.println(sum);
		}
	}
}